﻿using System;
using System.Collections;


namespace Sencha.Serialization.Bson
{
	public class ReadOnlyDictionary : IDictionary
	{
		private IDictionary m_innerDict;

		public ReadOnlyDictionary(IDictionary dictionary)
		{
			if (dictionary == null)
				throw new InvalidOperationException("dictionary");

			m_innerDict = dictionary;
		}

		#region IDictionary Members

		public void Add(object key, object value)
		{
			throw new NotSupportedException();
		}

		public void Clear()
		{
			throw new NotSupportedException();
		}

		public bool Contains(object key)
		{
			return m_innerDict.Contains(key);
		}

		public IDictionaryEnumerator GetEnumerator()
		{
			return m_innerDict.GetEnumerator();
		}

		public bool IsFixedSize
		{
			get { return true; }
		}

		public bool IsReadOnly
		{
			get { return true; }
		}

		public ICollection Keys
		{
			get { return m_innerDict.Keys; }
		}

		public void Remove(object key)
		{
			throw new NotSupportedException();
		}

		public ICollection Values
		{
			get { return m_innerDict.Values; }
		}

		public object this[object key]
		{
			get
			{
				return m_innerDict[key];
			}
			set
			{
				throw new NotSupportedException();
			}
		}

		#endregion

		#region ICollection Members

		public void CopyTo(Array array, int index)
		{
			m_innerDict.CopyTo(array, index);
		}

		public int Count
		{
			get { return m_innerDict.Count; }
		}

		public bool IsSynchronized
		{
			get {return m_innerDict.IsSynchronized; }
		}

		public object SyncRoot
		{
			get { return m_innerDict.SyncRoot; }
		}

		#endregion

		#region IEnumerable Members

		IEnumerator IEnumerable.GetEnumerator()
		{
			return m_innerDict.GetEnumerator();
		}

		#endregion
	}
}
